/*
 * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *      http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package me.ahoo.wow.test.saga.stateless

import me.ahoo.wow.event.DomainEventExchange
import me.ahoo.wow.saga.stateless.CommandStream

/**
 * Represents the expected result of a stateless saga processing operation.
 *
 * This data class encapsulates the outcome of processing a domain event through
 * a stateless saga, including the event exchange, processor, generated commands,
 * and any errors that occurred.
 *
 * @param T The type of the saga processor.
 * @property exchange The domain event exchange that triggered the saga processing.
 * @property processor The saga processor instance that handled the event.
 * @property commandStream The stream of commands generated by the saga, or null if none.
 * @property error Any error that occurred during processing, or null if successful.
 */
data class ExpectedResult<T : Any>(
    val exchange: DomainEventExchange<*>,
    val processor: T,
    val commandStream: CommandStream?,
    val error: Throwable? = null
) : StatelessSagaExpecter<T, ExpectedResult<T>> {
    /**
     * Indicates whether an error occurred during saga processing.
     */
    val hasError = error != null

    override fun expect(expected: ExpectedResult<T>.() -> Unit): ExpectedResult<T> {
        expected(this)
        return this
    }
}
